package at.pervasive.mp3player.actions;

import java.awt.event.ActionEvent;
import java.io.File;
import java.util.Arrays;
import java.util.List;

import javax.swing.JFileChooser;

import at.pervasive.mp3player.Mp3Player;

public class AddFilesAction extends AbstractMp3PlayerAction
{

	private File lastSelectedDir;

	public AddFilesAction(Mp3Player player)
	{
		super(player);

		putValue(LARGE_ICON_KEY, getIcon("add.png"));
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		JFileChooser fileChooser = new JFileChooser(lastSelectedDir);
		fileChooser.setMultiSelectionEnabled(true);
		int option = fileChooser.showOpenDialog(null);
		if (option == JFileChooser.APPROVE_OPTION)
		{
			lastSelectedDir = fileChooser.getCurrentDirectory();
			File[] selectedFiles = fileChooser.getSelectedFiles();
			List<File> list = Arrays.asList(selectedFiles);
			player.add(list);
		}
	}

}
